package antistatic.spinnerwheel.adapters;

import android.content.Context;

public class NumericWheelAdapter extends AbstractWheelTextAdapter {
	public static final int DEFAULT_MAX_VALUE = 9;
	private static final int DEFAULT_MIN_VALUE = 0;
	private String format;
	private int maxValue;
	private int minValue;

	public NumericWheelAdapter(Context context) {
		this(context, 0, 9);
	}

	public NumericWheelAdapter(Context context, int minValue, int maxValue) {
		this(context, minValue, maxValue, null);
	}

	public NumericWheelAdapter(Context context, int minValue, int maxValue, String format) {
		super(context);
		this.minValue = minValue;
		this.maxValue = maxValue;
		this.format = format;
	}

	public void setMinValue(int minValue) {
		this.minValue = minValue;
		notifyDataInvalidatedEvent();
	}

	public void setMaxValue(int maxValue) {
		this.maxValue = maxValue;
		notifyDataInvalidatedEvent();
	}

	@Override
	public CharSequence getItemText(int index) {
		if (index < 0 || index >= getItemsCount()) {
			return null;
		}
		int value = this.minValue + index;
		if (this.format == null) {
			return Integer.toString(value);
		}
		return String.format(this.format, new Object[] { Integer.valueOf(value) });
	}

	public int getItemsCount() {
		return (this.maxValue - this.minValue) + 1;
	}
}